package com.itfenghuang.controller;

import com.itfenghuang.bean.User;
import com.itfenghuang.service.UserService;
import com.itfenghuang.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class UserServlet extends HttpServlet {
    private UserService service=new UserServiceImp();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;charset=utf-8");
       //获取请求参数
        String id = req.getParameter("id");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //将集合存到请求域中,然后转发到selectUser.jsp上
        User user = new User();
        user.setId(Integer.parseInt(id));
        user.setUsername(username);
        user.setPassword(password);
        List<User> list = service.selectUser(user);
        if (list!=null && !list.isEmpty()){
            req.setAttribute("userList",list);
            req.getRequestDispatcher("/selectUser.jsp").forward(req,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
    }
}
